//
//  RadioTableViewCell.m
//  时光
//
//  Created by dllo on 16/3/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "RadioTableViewCell.h"
#import "RadioCollectionViewCell.h"
@implementation RadioTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatCollection];
       
    }
    return self;
}

- (void)creatCollection{
    self.layout = [[UICollectionViewFlowLayout alloc] init];
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT * 0.3) collectionViewLayout:self.layout];
    self.collection.dataSource = self;
    self.collection.delegate = self;
    [self.contentView addSubview:self.collection];
    
    self.layout.itemSize = CGSizeMake(WIDTH / 3 - 1, HEIGHT / 4);
    self.layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.layout.minimumInteritemSpacing = 5;
    self.layout.minimumLineSpacing = 2;
    
    [self.collection registerClass:[RadioCollectionViewCell class] forCellWithReuseIdentifier:@"RadioCollectionViewCell"];
  
    self.array = [NSMutableArray array];
    
    
}

- (void)setModel:(RadioModel *)model{
    [self.array addObject:model];
}



- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    RadioCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RadioCollectionViewCell" forIndexPath:indexPath];
    RadioModel *model = self.array[indexPath.row];
//    NSLog(@"%@", model.title);
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [self.delegate sender:@"122"];
}

@end
